import request from '@/config/axios'

// 商家信息 VO
export interface MerchantVO {
  id: number // 主键ID
  merchantName: string // 商家名称
  contactPerson: string // 联系人
  phone: string // 联系电话
  email: string // 电子邮箱
  address: string // 地址
  status: number // 状态
  balance?: number // 备款余额
}

// 商家信息 API
export const MerchantApi = {
  // 查询商家信息分页
  getMerchantPage: async (params: any) => {
    return await request.get({ url: `/juliang/merchant/page`, params })
  },

  // 查询商家信息详情
  getMerchantById: async (id: number) => {
    return await request.get({ url: `/juliang/merchant/getById?id=` + id })
  },

  // 新增商家信息
  createMerchant: async (data: MerchantVO) => {
    return await request.post({ url: `/juliang/merchant/create`, data })
  },

  // 修改商家信息
  updateMerchant: async (data: MerchantVO) => {
    return await request.post({ url: `/juliang/merchant/update`, data })
  },

  // 修改商家信息状态
  updateMerchantStatus: async (id: number, status: number) => {
    const data = {
      id,
      status
    }
    return await request.post({ url: `/juliang/merchant/updateStatus`, data: data })
  },

  // 删除商家信息
  deleteMerchantById: async (id: number) => {
    return await request.get({ url: `/juliang/merchant/delete?id=` + id })
  },

  // 导出商家信息 Excel
  exportMerchant: async (params) => {
    return await request.download({ url: `/juliang/merchant/export-excel`, params })
  },

  // 发送催款通知
  sendDunningNotice: async (data: any) => {
    return await request.post({ url: `/juliang/merchant/sendDunningNotice`, data })
  },

  // 封禁/解封商家账号
  banMerchantAccount: async (id: number, status: number) => {
    const data = {
      id,
      status
    }
    return await request.post({ url: `/juliang/merchant/banAccount`, data: data })
  },

  // 转账
  transferBalance: async (data: {
    fromMerchantId: number
    toMerchantId: number
    amount: number
    remark?: string
  }) => {
    return await request.post({ url: `/juliang/merchant/transfer`, data })
  },

  // 获取可转账商家列表
  getTransferableMerchants: async (params: {
    pageNo: number
    pageSize: number
    excludeMerchantId?: number
    merchantName?: string
  }) => {
    return await request.get({ url: `/juliang/merchant/page`, params })
  },

  // 根据商家ID获取账户列表
  getMerchantAccounts: async (params: {
    pageNo: number
    pageSize: number
    merchantId: number
    queryBeikuanAccount?: boolean
  }) => {
    return await request.get({ url: `/juliang/account-balance/page`, params })
  }
}
